using System.Collections;
using System.Collections.Generic;
using Commons.Models.Definitions;
using Commons.Models.Settings.Dtos;
using Commons.Models.Settings.Dtos.Stats;
using Commons.Models.Settings.Mappers;
using Commons.Models.Settings.Mappers.Stats;

namespace Commons.Models.Settings.Parsers
{
	public class GeneralSettingsParser : BaseSettingsParser<GameConfigDto>
	{
		public GeneralSettingsParser()
			: base("Data/shared/general-config")
		{
		}

		public override IEnumerator Parse(ParserContext context, ISettingsModel settingsModel)
		{
			GameConfigDto config = Deserialize();
			yield return null;

			if (config.Stats.LeveledStats != null)
			{
				TotalObjects += config.Stats.LeveledStats.Count;
			}
			// user stats definitions
			List<IStatDefinition> stats = new List<IStatDefinition>();

			if (config.Stats.SimpleStats != null)
			{
				SimpleStatMapper mapper = new SimpleStatMapper();
				foreach (SimpleStatDto stat in config.Stats.SimpleStats)
				{
					stats.Add(mapper.Map(stat));

					NumObjects++;

					yield return null;
				}
			}
			if (config.Stats.LeveledStats != null)
			{
				LeveledStatMapper mapper = new LeveledStatMapper();
				foreach (LeveledStatDto stat in config.Stats.LeveledStats)
				{
					stats.Add(mapper.Map(stat));

					NumObjects++;

					yield return null;
				}
			}
			
			settingsModel.AddSetting(new StatSettings(stats));
		}
	}
}

